package spring.lottery.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import spring.lottery.common.pojo.ResponseMode;
import spring.lottery.controller.param.DrawPrizesData;
import spring.lottery.server.DrawPrizeServer;
import spring.lottery.server.dto.WinningsDto;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping
public class DrawPrizeController {

    @Autowired
    DrawPrizeServer drawPrizeServer;

    /**
     * 查询活动内容
     * 还不知道他要啥
     * @return
     */
    @RequestMapping("/activity-detail/find")
    public ResponseMode find(@NotNull Long activityId) {
        return ResponseMode.success(drawPrizeServer.find(activityId));
    }

    /**
     * 如果传了俩个参数，activityId 和 prizeId，那么就只差这几个
     * @param params
     * @return List: winnerName prizeName prizeTier
     */
    @RequestMapping("/winning-records/show")
    public ResponseMode showWinning(@NotNull @RequestBody Map<String,String> params) {

        log.info("/winning-records/show收到请求: {}", params);

        List<WinningsDto> winningsDtos = drawPrizeServer.showWinning(params);

        return ResponseMode.success(winningsDtos);
    }

    /**
     * 储存中奖人
     */
    @RequestMapping("/draw-prize")
    public ResponseMode drawPrize(@Valid @RequestBody DrawPrizesData drawPrizesData) {
        log.info("/draw-prize收到请求: {}", drawPrizesData);
        //这里就要到传说中的扭转奖品状态了

        //把中将的信息发送到mq中，等待消费者处理
        drawPrizeServer.sendToMq(drawPrizesData);

        return ResponseMode.success(true);
    }


}
